home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / admin / dig-2.0 / dig-2 / dig.2.0 / strcasecmp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-04  |  3.1 KB  |  78 lines

  1. /*
  2.  * Copyright (c) 1987 Regents of the University of California.
  3.  * All rights reserved.  The Berkeley software License Agreement
  4.  * specifies the terms and conditions for redistribution.
  5.  */
  6.  
  7. /*
  8. ** Distributed with 'dig' version 2.0 from University of Southern
  9. ** California Information Sciences Institute (USC-ISI). 9/1/90
  10. */
  11.  
  12. #if defined(LIBC_SCCS) && !defined(lint)
  13. static char sccsid[] = "@(#)strcasecmp.c    1.3 (Berkeley) 8/3/87";
  14. #endif LIBC_SCCS and not lint
  15.  
  16. /*
  17.  * This array is designed for mapping upper and lower case letter
  18.  * together for a case independent comparison.  The mappings are
  19.  * based upon ascii character sequences.
  20.  */
  21. static char charmap[] = {
  22.     '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
  23.     '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
  24.     '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
  25.     '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
  26.     '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
  27.     '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
  28.     '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
  29.     '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
  30.     '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
  31.     '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
  32.     '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
  33.     '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
  34.     '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
  35.     '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
  36.     '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
  37.     '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
  38.     '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
  39.     '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
  40.     '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
  41.     '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
  42.     '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
  43.     '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
  44.     '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
  45.     '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
  46.     '\300', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
  47.     '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
  48.     '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
  49.     '\370', '\371', '\372', '\333', '\334', '\335', '\336', '\337',
  50.     '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
  51.     '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
  52.     '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
  53.     '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
  54. };
  55.  
  56. strcasecmp(s1, s2)
  57.     register char *s1, *s2;
  58. {
  59.     register char *cm = charmap;
  60.  
  61.     while (cm[*s1] == cm[*s2++])
  62.         if (*s1++ == '\0')
  63.             return(0);
  64.     return(cm[*s1] - cm[*--s2]);
  65. }
  66.  
  67. strncasecmp(s1, s2, n)
  68.     register char *s1, *s2;
  69.     register int n;
  70. {
  71.     register char *cm = charmap;
  72.  
  73.     while (--n >= 0 && cm[*s1] == cm[*s2++])
  74.         if (*s1++ == '\0')
  75.             return(0);
  76.     return(n < 0 ? 0 : cm[*s1] - cm[*--s2]);
  77. }
  78.